//
//  ReceiveOrderCell.swift
//  newShaohuoRen
//
//  Created by hujinbiao on 2018/3/22.
//  Copyright © 2018年 hujinbiao. All rights reserved.
//

import UIKit

class ReceiveOrderCell: UITableViewCell {

    //帮买
    @IBOutlet weak var mutableOrderImgView: UIImageView!
    //预约时间
    @IBOutlet weak var appointTimeLabel: UILabel!
    //价格
    @IBOutlet weak var priceLabel: UILabel!
    //取件地址
    @IBOutlet weak var sendAddressLabel: UILabel!
    //派件地址
    @IBOutlet weak var recvAddressLabel: UILabel!
    //时间
    @IBOutlet weak var timeLabel: UILabel!
    //备注
    @IBOutlet weak var remarkLabel: UILabel!
    
    @IBOutlet weak var recvOrderButton: FlatButton!
    
    @IBOutlet weak var myDistanceLabel: UILabel!
    
    @IBOutlet weak var distanceLabel: UILabel!
    
    @IBOutlet weak var itemNameLabel: UILabel!
    @IBOutlet weak var recordButton: UIButton!
    
    @IBOutlet weak var recordButtonWidth: NSLayoutConstraint!
    
    var recoder_manager = RecordManager()//初始化
    
    var orderTypeArray = ["receive_buy_order","receive_order","receive_luntai_order","receive_homeservice_order","receive_paidui_order","receive_liyi_order","receive_driver_order"]
    
    override func awakeFromNib() {
        super.awakeFromNib()
        
    }
    
    var _ordersItem : OrdersDataItem?
    
    var ordersItem : OrdersDataItem? {
        get {
            return _ordersItem
        }
        set {
            _ordersItem = newValue
            mutableOrderImgView.image = UIImage(named: orderTypeArray[(Int((_ordersItem?.fc_id)!)!-1)])
            appointTimeLabel.text = "\(_ordersItem!.book_time_str)"
            priceLabel.text = "￥\(_ordersItem!.shipping_fee)元"

            if _ordersItem?.video_time=="-1"{//文字
                recordButton.isHidden = true
                itemNameLabel.isHidden = false
                itemNameLabel.text = "商品名称：\(_ordersItem!.item_name)"
            }else {//语音
                itemNameLabel.isHidden = true
                recordButton.isHidden = false
                recordButton.setTitle("\(_ordersItem!.video_time)''", for: .normal)
                recordButtonWidth.constant = CGFloat(Int(_ordersItem!.video_time)!*10+40)
            }
            
            if !((_ordersItem?.start_addr.isEmpty)!) {
                sendAddressLabel.text = "取：\(_ordersItem!.start_addr)"
            }else {
                sendAddressLabel.text = ""
            }
            if !((_ordersItem?.end_addr.isEmpty)!) {
                recvAddressLabel.text = "派：\(_ordersItem!.end_addr)"
            }else if !((_ordersItem?.serve_addr.isEmpty)!) {
                recvAddressLabel.text = "派：\(_ordersItem!.serve_addr)"
            }else {
                recvAddressLabel.text = ""
            }
            timeLabel.text = "预约时间：\(_ordersItem!.book_time)"
            if !((_ordersItem?.remark.isEmpty)!){
                remarkLabel.text = _ordersItem?.remark
            }else{
                remarkLabel.text = "空"
            }
            myDistanceLabel.text = _ordersItem?.distance
            distanceLabel.text = _ordersItem?.distance
        }
    }
    
    //播放语音
    @IBAction func recordBtnAction(_ sender: UIButton) {
        recoder_manager.playRecoder(filePath: "\(endpoint)\(_ordersItem!.item_name)")
    }
    
}
